class PostsController < ApplicationController
  
  # Prikaz svih postova
  def index
    @posts = Post.all
  end

  # Prikaz pojedinog posta /posts/:id:
  def show
    @post = Post.find(params[:id])
    @members = Member.all
  end

  # Obrazac za unos posta
  def new
    @post = Post.new
  end

  # Obraza za uredjivanje posta
  def edit
    @post = Post.find(params[:id])
  end

  # Stvaranje posta
  def create
    @post = Post.new(params[:post])

    if @post.save
      redirect_to(@post, :notice => 'Post was successfully created.') 
    else
      render :action => "new"
    end
  end

  # Update posta
  def update
    @post = Post.find(params[:id])

    if @post.update_attributes(params[:post])
      redirect_to(@post, :notice => 'Post was successfully updated.')
    else
      render :action => "edit"
    end
  end

  # Brisanje posta
  def destroy
    @post = Post.find(params[:id])
    @post.destroy

    redirect_to(posts_url) 
  end
  
  # Usporedba sa clanom
  def compare
    
    
    @post = Post.find(params[:post_id])
    @member = Member.find(params[:member_id])
    @tags_in_common = @member.tags_in_common @post
    @similarity = @member.similarity @post
  end
end
